<?php
/**
 * 获得树形结构
 * @param  [type]  $data  [description]
 * @param  integer $pid   [description]
 * @param  integer $lenve [description]
 * @return [type]         [description]
 *///递归输出 '-'
function categoryTree($data,$pid=0,$lenve=0)
{
	// 设置静态数组
	static $arr = array();
	foreach ($data as $d) {
		if ($d['pid']==$pid) {
			$d['_cname'] = str_repeat('-', $lenve*3).$d['cname'];
			$arr[]=$d;
			categoryTree($data,$d['id'],$lenve+1);
		}
	}
	return $arr;
}

function p($data)
{
	echo '<pre>'.print_r($data,true);
}

?>